package com.cwt_taxi_xa;

import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TextView;

import com.cwt_taxi_xa.protocol.MCUUtil;
import com.cwt_taxi_xa.protocol.can.IViewVehicleInfo;
import com.cwt_taxi_xa.util.GPIOUtil;

public class ActivityCarInfo extends CWTBaseActivity implements IViewVehicleInfo {
	private String TAG = "ActivityCarInfo";
	private TextView tvGear,tvReady,tvReverse,tvFeatures,tvDoorState,tvBatteryPower,tvDrivingRange;
	private TextView tvTotalMileage,tvPowerConsumption,tvVehicleSpeed,tvDepth;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.openSwipeBack(true);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_aa_carinfo);
		//MCUUtil.mConditioningDecode.register(this);
		tvGear = (TextView)findViewById(R.id.tv_gear);
		tvReady = (TextView)findViewById(R.id.tv_ready_light);
		tvReverse = (TextView)findViewById(R.id.tv_reverse_light);
		tvFeatures = (TextView)findViewById(R.id.tv_features_light);
		tvDoorState = (TextView)findViewById(R.id.tv_door_state);
		tvBatteryPower = (TextView)findViewById(R.id.tv_battery_power);
		tvDrivingRange = (TextView)findViewById(R.id.tv_driving_range);
		tvTotalMileage = (TextView)findViewById(R.id.tv_total_mileage);
		tvPowerConsumption = (TextView)findViewById(R.id.tv_power_consumption);
		tvVehicleSpeed = (TextView)findViewById(R.id.tv_vehicle_speed);
		tvDepth = (TextView)findViewById(R.id.tv_depth);
		MCUUtil.mVehicleInformation.register(this);
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		//背光全部
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		//背光
		MCUUtil.mVehicleInformation.unregister(this);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void setStatus(int index, boolean status) {
		// TODO Auto-generated method stub

	}

	@Override
	public void sendMsg(int type, Object obj) {
		// TODO Auto-generated method stub

	}

	@Override
	public void gearPosition(int value) {
		tvGear.setText((value == 2?"R档":"保留"));
	}

	@Override
	public void readyLight(int value) {
		if(value == 1){
			tvReady.setText("显示");
		}else if(value == 0){
			tvReady.setText("不显示");
		}else{
			tvReady.setText("保留");
		}

	}

	@Override
	public void reverseLight(int value) {
		if(value == 1){
			tvReverse.setText("倒车灯点亮");
		}else if(value == 0){
			tvReverse.setText("无效");
		}else if(value == 2){
			tvReverse.setText("倒车灯熄灭");
		}else{
			tvReverse.setText("保留");
		}
	}

	@Override
	public void featuresLight(int nearLight, int farLight, int leftLight, int rightLightValue) {
		StringBuffer buffer = new StringBuffer();
		buffer.append("近光灯:");
		buffer.append((nearLight == 1?"打开":"关闭"));
		buffer.append(";");
		buffer.append("远光灯:");
		buffer.append((farLight == 1?"打开":"关闭"));
		buffer.append(";");
		buffer.append("左转向灯:");
		buffer.append((leftLight == 1?"打开":"关闭"));
		buffer.append(";");
		buffer.append("右转向灯:");
		buffer.append((rightLightValue == 1?"打开":"关闭"));
		tvFeatures.setText(buffer.toString());
	}

	@Override
	public void doorState(int rightFrontDoor, int leftBackDoor, int rightBackDoor, int trunkDoor, int brakePedalStatus) {
		StringBuffer buffer = new StringBuffer();
		buffer.append("右前门状态:");
		buffer.append((rightFrontDoor == 1?"开":"关"));
		buffer.append(";");
		buffer.append("左后门状态:");
		buffer.append((leftBackDoor == 1?"开":"关"));
		buffer.append(";");
		buffer.append("右后门状态:");
		buffer.append((rightBackDoor == 1?"开":"关"));
		buffer.append(";");
		buffer.append("行李箱状态:");
		buffer.append((trunkDoor == 1?"开":"关"));
		buffer.append(";");
		buffer.append("制动踏板状态:");
		buffer.append((brakePedalStatus == 1?"Pressed":"Not Pressed"));
		tvDoorState.setText(buffer.toString());
	}

	@Override
	public void batteryPower(double value) {
		tvBatteryPower.setText(String.format("%.4f", value));
	}

	@Override
	public void drivingRange(int value) {
		tvDrivingRange.setText(value + "");
	}

	@Override
	public void totalMileage(int value) {
		tvTotalMileage.setText(String.valueOf(value));
	}

	@Override
	public void powerConsumption(double value) {
		tvPowerConsumption.setText(String.format("%.4f",value));
	}

	@Override
	public void vehicleSpeed(double value) {
		tvVehicleSpeed.setText(String.format("%.4f", value));
	}

	@Override
	public void depth(int accelerator, int brake) {
		StringBuffer buffer = new StringBuffer();
		buffer.append("油门深度:");
		buffer.append((accelerator == 1?"有效":"无效"));
		buffer.append(";");
		buffer.append("制动深度:");
		buffer.append((brake == 1?"有效":"无效"));
		tvDepth.setText(buffer.toString());
	}
}
